package com.coocaa.typhoon.api.v1.milvus.service.sync;

import cn.hutool.core.bean.BeanUtil;
import com.coocaa.cirrus.common.base.util.IdCreateUtil;
import com.coocaa.typhoon.api.third.volcengine.model.output.UserFileVO;
import com.coocaa.typhoon.api.third.volcengine.service.VikingDbUserFileService;
import com.coocaa.typhoon.api.v1.mysql.model.entity.UserFileEntity;
import com.coocaa.typhoon.api.v1.userfile.model.input.GetSearchDataModel;
import com.coocaa.typhoon.api.v1.userfile.util.TosFinalUrlUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author bijiahao
 * @date : 2025/9/26 08:47
 * @description
 */
@Service
public class InitSyncService {
    @Autowired
    private VikingDbUserFileService vikingDbUserFileService;
    @Autowired
    private UserFileSyncService userFileSyncService;

    public void init(String userId) {
        GetSearchDataModel dataModel = new GetSearchDataModel();
        dataModel.setUserId(userId);
        dataModel.setStartDate("2025-09-20 08:00:00");
        List<UserFileVO> userFileVOList = vikingDbUserFileService.search(dataModel);
        for (UserFileVO userFileVO : userFileVOList) {
            UserFileEntity entity = new UserFileEntity();
            BeanUtil.copyProperties(userFileVO, entity);
            entity.setId(IdCreateUtil.getStrId());
            entity.setFilePath(TosFinalUrlUtil.getFilePath(userFileVO.getTosLink()));
            userFileSyncService.sync(entity);
        }
    }
}
